<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
</head>
<body>
    <div id="app">
    <cpn></cpn> 
    <cpn ref="ref1"></cpn>  
    <cpn></cpn>     
    <button @click="showMessage">click</button>
    </div>
    <!--  -->
    <template id="cpnT">
        <div>
            <h2>我是组件</h2>
        </div>
    </template>
    <!--  -->
    <script>
        var app = new Vue({
            el: "#app",
            data: {
                name: "tina sl"
            },
            methods: {
                showMessage(){
                    // console.log("showMessage");
                    // ----- method 1:
                    // console.log(this.$children[0].name);
                    // ----- method 2:
                    // for (let index = 0; index < this.$children.length; index++) {
                    //     const element = this.$children[index];
                    //     console.log(element.name);
                    // }
                    // ---- method 3($refs):
                    console.log(this.$refs.ref1.name);
                }
            },
            components: {
                cpn: {
                    template: "#cpnT",
                    data(){
                        return{
                            name: "nameMessage",
                        }
                    }
                }
            }
        })
    </script>
</body>
</html>